//空间信息(json)
var spaceInfo=[50,100,200,500,1000];
//时间信息(json)
var periodInfo=[1,2,3,4,5,6,7,8,9,10,11,12];
$(function(){


//动态生成滑动条区间尺码
var spaceHtml=$("<div class='unitdiv'></div>");//M&nbsp; slider
var spaceHtml_1=$("<div class='unitdiv'></div>");//M&nbsp; slider
var spaceHtml_2=$("<div class='unitdiv'></div>");//M&nbsp; slider
var timeHtml=$("<div class='unitdiv' ></div>");//&nbsp; slider_time
var timeHtml_1=$("<div class='unitdiv' ></div>");//&nbsp; slider_time
var timeHtml_2=$("<div class='unitdiv' ></div>");//&nbsp; slider_time
var spaceWidth=parseInt(100/spaceInfo.length);
var timeWidth=Math.floor(100/periodInfo.length);

//空间
for(var i=0;i<spaceInfo.length;i++){
var prototype=$(spaceHtml).clone();
prototype.html(spaceInfo[i]+"M&nbsp;").css("width",spaceWidth-0.1+"%");
$("#slider").append(prototype);
if(i==spaceInfo.length-1)
$("#slider .unitdiv:last").css("border-right","0px");
}
//续租
for(var i=0;i<spaceInfo.length;i++){
var prototype=$(spaceHtml_1).clone();
prototype.html(spaceInfo[i]+"M&nbsp;").css("width",spaceWidth-0.1+"%");
$("#slider_1").append(prototype);
if(i==spaceInfo.length-1)
$("#slider_1 .unitdiv:last").css("border-right","0px");
}
//加速
for(var i=0;i<spaceInfo.length;i++){
var prototype=$(spaceHtml_2).clone();
prototype.html(spaceInfo[i]+"M&nbsp;").css("width",spaceWidth-0.1+"%");
$("#slider_2").append(prototype);
if(i==spaceInfo.length-1)
$("#slider_2 .unitdiv:last").css("border-right","0px");
}
//时间
for(var i=0;i<periodInfo.length;i++){
var prototype=$(timeHtml).clone();
// prototype.html(i+1+"月 &nbsp;").css("width",timeWidth-1+"%");
prototype.html(periodInfo[i]+"月&nbsp;").css("width",timeWidth+"%");
$("#slider_time").append(prototype);//扩容续租
$("#slider_cache_time_cdn").append(prototype).clone();//加速界面
if(i==periodInfo.length-1){
$("#slider_time .unitdiv:last").css("border-right","0px");//扩容续租
$("#slider_cache_time_cdn .unitdiv:last").css("border-right","0px");}//加速界面
}
//续租
for(var i=0;i<periodInfo.length;i++){
var prototype=$(timeHtml_1).clone();
// prototype.html(i+1+"月 &nbsp;").css("width",timeWidth-1+"%");
prototype.html(periodInfo[i]+"月&nbsp;").css("width",timeWidth+"%");
$("#slider_time_1").append(prototype);//扩容续租
$("#slider_cache_time_cdn").append(prototype).clone();//加速界面
if(i==periodInfo.length-1){
$("#slider_time_1 .unitdiv:last").css("border-right","0px");//扩容续租
$("#slider_cache_time_cdn .unitdiv:last").css("border-right","0px");}//加速界面
}

//加速
for(var i=0;i<periodInfo.length;i++){
var prototype=$(timeHtml_2).clone();
// prototype.html(i+1+"月 &nbsp;").css("width",timeWidth-1+"%");
prototype.html(periodInfo[i]+"月&nbsp;").css("width",timeWidth+"%");
$("#slider_time_2").append(prototype);//扩容续租
if(i==periodInfo.length-1){
$("#slider_time_2 .unitdiv:last").css("border-right","0px");//扩容续租
}
}
});
    //计价
function stairPrice(){

   var price=10;//  10元/M/月

    create_section();
    
    //区间段
    var spaceSectionNum=$("#spaceSectionNum").val();
    var timeSectionNum=$("#timeSectionNum").val();
    //购买量
    var spaceTotal=$("#tot_volume").val();
    var timeTotal=$("#buy_num").val();
    
    var cost_money=price*spaceTotal*timeTotal;
   
    
    var gnum = '';
    var gstr = '';
          timeTotal=(timeTotal>=1?timeTotal:1);
          for(var k in periodInfo)
          {
                    if(timeTotal==periodInfo[k]){
                       gnum = periodInfo[k];
                      
                      break;
                      }
          }


             //计算费用
            var cost_money_str = '存储容量：'+spaceTotal+'M ('+price+'元/M/月) * 使用时长：'+timeTotal+'个月';//+'='+cost_money+'元';;
            //+'= 总计：'+cost_money;
            var pDate = getPDate(parseInt(timeTotal-1));//有效期限
           

             cost_money_str+='= 总计：<span class="colC"><em class="f20">'+cost_money+'</em></span> 元';
    
            //模板赋值
            $("#cost_money").val(cost_money);//隐蔽域存放金额
            $("#pDate").html(pDate);
            $("#cost_money_show").html(cost_money_str);
            $("#cost_money_show").show();
            $(".i-month").html(timeTotal)

    }
  
  function stairPrice_1(){
  
   var price=10;//  10元/M/月

    create_section_1();
    
    //区间段
    var spaceSectionNum=$("#spaceSectionNum").val();
    var timeSectionNum=$("#timeSectionNum").val();
    //购买量
    var spaceTotal_1=$("#tot_volume_1").val();
    var timeTotal_1=$("#buy_num_1").val();
    
    var cost_money_1=price*spaceTotal_1*timeTotal_1;
   
    
    var gnum_1 = '';
    var gstr_1 = '';
          timeTotal_1=(timeTotal_1>=1?timeTotal_1:1);
          for(var k in periodInfo)
          {
                    if(timeTotal_1==periodInfo[k]){
                       gnum_1 = periodInfo[k];
                      
                      break;
                      }
          }

             //计算费用

            var cost_money_str_1 = '续租容量：'+spaceTotal_1+'M ('+price+'元/M/月) * 时长：'+timeTotal_1+'个月';//+'='+cost_money+'元';;
            var pDate_1 = getPDate(parseInt(timeTotal_1-1));//有效期限
           

             cost_money_str_1+='= 总计：'+cost_money_1;
  

            //模板赋值
            // $("#cost_money_1").val(cost_money);//隐蔽域存放金额
            $("#pDate_1").html(pDate_1);
            $("#cost_money_show_1").html(cost_money_str_1);
            $("#cost_money_show_1").show();
    }
  
  function stairPrice_2(){
  
   var price=10;//  10元/M/月

    create_section_2();
    
    //区间段
    var spaceSectionNum=$("#spaceSectionNum").val();
    var timeSectionNum=$("#timeSectionNum").val();
    //购买量
    var spaceTotal_2=$("#tot_volume_2").val();
    var timeTotal_2=$("#buy_num_2").val();
    
    var cost_money_2=price*spaceTotal_2*timeTotal_2;
   
    
    var gnum_2 = '';
    var gstr_2 = '';
          timeTotal_2=(timeTotal_2>=1?timeTotal_2:1);
          for(var k in periodInfo)
          {
                    if(timeTotal_2==periodInfo[k]){
                       gnum_2 = periodInfo[k];
                      
                      break;
                      }
          }

             //计算费用

            var cost_money_str_2 = '容量：'+spaceTotal_2+'M ('+price+'元/M/月) * 时长：'+timeTotal_2+'个月';//+'='+cost_money+'元';;
            var pDate_2 = getPDate(parseInt(timeTotal_2-1));//有效期限
           

             cost_money_str_2+='= 总计：'+cost_money_2;
  

            //模板赋值
            $("#cost_money_2").val(cost_money);//隐蔽域存放金额
            $("#pDate_2").html(pDate_2);
            $("#cost_money_show_2").html(cost_money_str_2);
            $("#cost_money_show_2").show();
    }


   //续租
    function create_section_1(){
      //购买量
      var spaceTotal=$("#tot_volume").val();
      var timeTotal=$("#buy_num").val();
      
           //获取手动输入的容量值
      var sid_1=0;
      var tot_volume_1 = parseInt($("#tot_volume").val());
      var max_volume_1 = spaceInfo[spaceInfo.length-1]//'1000';
      var min_volume_1 = spaceInfo[0]//'10';
                
                
     var num_1 = spaceInfo.length;
              if(tot_volume_1 > max_volume_1){
                  $("#tot_volume_1").val(max_volume_1);
                  sid_1 = spaceInfo.length-1;
              }else if(tot_volume_1 < min_volume_1){
                  $("#tot_volume_1").val(min_volume_1);
                  sid_1 = 0;
              }else{
                 for(var key in spaceInfo){
                    if((tot_volume_1 >= spaceInfo[key]) && (tot_volume_1 <= spaceInfo[key+1])){
                       sid_1 = parseInt(key);
                      
                      break;
                    }
                 }
              }
              
             var tid_1 =0;
             var buy_num_1 = parseInt($("#buy_num_1").val());
             var max_month_1 = periodInfo[periodInfo.length-1];
             var min_month_1 = periodInfo[0];

             if(buy_num_1>max_month_1){
                 $("#buy_num_1").val(max_month_1);
                 tid_1=periodInfo.length-1;
                 
             }else if(buy_num_1<min_month_1){
                 $("#buy_num_1").val(min_month_1);
                 tid_1=0;
             }
             else{
                  for(var key in periodInfo){
                    if(buy_num_1 = periodInfo[key]){
                       tid_1 = parseInt(key);
                      break;
                    }
             }
    }
      $("#spaceSectionNum_1").val(++sid_1);//空间区间
      $("#timeSectionNum_1").val(++tid_1);//时间区间

    
    }
   //加速
    function create_section_2(){
      //购买量
      var spaceTotal=$("#tot_volume").val();
      var timeTotal=$("#buy_num").val();
      
           //获取手动输入的容量值
      var sid_2=0;
      var tot_volume_2 = parseInt($("#tot_volume").val());
      var max_volume_2 = spaceInfo[spaceInfo.length-1]//'1000';
      var min_volume_2 = spaceInfo[0]//'10';
                
                
     var num_2 = spaceInfo.length;
              if(tot_volume_2 > max_volume_2){
                  $("#tot_volume_2").val(max_volume_2);
                  sid_2 = spaceInfo.length-1;
              }else if(tot_volume_2 < min_volume_2){
                  $("#tot_volume_2").val(min_volume_2);
                  sid_2 = 0;
              }else{
                 for(var key in spaceInfo){
                    if((tot_volume_2 >= spaceInfo[key]) && (tot_volume_2 <= spaceInfo[key+1])){
                       sid_2 = parseInt(key);
                      
                      break;
                    }
                 }
              }
              
             var tid_2 =0;
             var buy_num_2 = parseInt($("#buy_num_2").val());
             var max_month_2 = periodInfo[periodInfo.length-1];
             var min_month_2 = periodInfo[0];

             if(buy_num_2>max_month_2){
                 $("#buy_num_2").val(max_month_2);
                 tid_2=periodInfo.length-1;
                 
             }else if(buy_num_2<min_month_2){
                 $("#buy_num_2").val(min_month_2);
                 tid_2=0;
             }
             else{
                  for(var key in periodInfo){
                    if(buy_num_2 = periodInfo[key]){
                       tid_2 = parseInt(key);
                      break;
                    }
             }
    }
      $("#spaceSectionNum_2").val(++sid_2);//空间区间
      $("#timeSectionNum_2").val(++tid_2);//时间区间

    
    }



        function create_section(){
      //购买量
      var spaceTotal=$("#tot_volume").val();
      var timeTotal=$("#buy_num").val();
      
           //获取手动输入的容量值
      var sid=0;
      var tot_volume = parseInt($("#tot_volume").val());
      var max_volume = spaceInfo[spaceInfo.length-1]//'1000';
      var min_volume = spaceInfo[0]//'10';
                
                
     var num = spaceInfo.length;
              if(tot_volume > max_volume){
                  $("#tot_volume").val(max_volume);
                  sid = spaceInfo.length-1;
              }else if(tot_volume < min_volume){
                  $("#tot_volume").val(min_volume);
                  sid = 0;
              }else{
                 for(var key in spaceInfo){
                    if((tot_volume >= spaceInfo[key]) && (tot_volume <= spaceInfo[key+1])){
                       sid = parseInt(key);
                      
                      break;
                    }
                 }
              }
              
             var tid =0;
             var buy_num = parseInt($("#buy_num").val());
             var max_month = periodInfo[periodInfo.length-1];
             var min_month = periodInfo[0];

             if(buy_num>max_month){
                 $("#buy_num").val(max_month);
                 tid=periodInfo.length-1;
                 
             }else if(buy_num<min_month){
                 $("#buy_num").val(min_month);
                 tid=0;
             }
             else{
                  for(var key in periodInfo){
                    if(buy_num = periodInfo[key]){
                       tid = parseInt(key);
                      break;
                    }
             }
    }
      $("#spaceSectionNum").val(++sid);//空间区间
      $("#timeSectionNum").val(++tid);//时间区间

    
    }
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
//-------------空间结束 ------   
  //公共：
    //获取有效日期
        function getPDate(add_month){
            var m = new Date().getMonth()+1+parseInt(add_month); 
            var d = new Date(new Date().getFullYear(),m,new Date().getDate()); 
            var year = d.getFullYear();
            var month = d.getMonth()+1;
             if(month == 0){
               month = 12; 
               year = d.getFullYear()-1;
            }
            var day = d.getDate();
            var date = year + "年" + (month) + "月" + day + "日";

      var date1 = year + "-" + (month) + "-" + day;
      if(document.getElementById("end_time") != undefined)
      {
      console.log(document.getElementById("end_time").value);
      var end_time=document.getElementById("end_time").value=date1;
      }

            return date;
        }


    //容量计算
    $(document).ready(function() {
      
         $(".ui-slider-handle").html("<i></i><i></i><i></i>");

    var slider = $("#slider").slider({
            values:[],
            animate:true,
            min:0,
            max:1000,
            step:40,
            range:'min',
            change: function( event, ui ) {   
                  
                 // $("#tot_volume").val(parseInt(ui.value/2));
                 // alert(ui.value)

                 if(ui.value<200){
                  alert('对不起，最小存储容量不能小于50M');
                  $("#tot_volume").val(50);
                  

                }else if(ui.value<=400 && ui.value>200){
                  $("#tot_volume").val(100);
                             
                }else if(ui.value<=600 && ui.value>400){
                  $("#tot_volume").val(200)
                }else if(ui.value<=800 && ui.value>600){
                  $("#tot_volume").val(500)
                }else if(ui.value<=1000 && ui.value>800){
                  $("#tot_volume").val(1000);
                }


                 $(".re1_t1").html("&nbsp;M");
                // //计算费用
                 stairPrice();


            }
        });
     var slider_1 = $("#slider_1").slider({
            values:[],
            animate:true,
            min:0,
            max:1000,
            step:20,
            range:'min',
            change: function( event, ui ) {   
                  
                 $("#tot_volume_1").val(parseInt(ui.value));


                 $(".re1_t1").html("&nbsp;M");
                // //计算费用
                 stairPrice_1();


            }
        });
     var slider_2 = $("#slider_2").slider({
            values:[],
            animate:true,
            min:0,
            max:1000,
            step:20,
            range:'min',
            change: function( event, ui ) {   
                  
                 $("#tot_volume_2").val(parseInt(ui.value));


                 $(".re1_t1").html("&nbsp;M");
                // //计算费用
                 stairPrice_2();


            }
        });


        //拖拽时长滑条产生的费用计算
        var slider_time = $("#slider_time").slider({
            values:[],
            animate:true,
            min:0,
            max:12,
            step:1,
            range:'min',
            change: function( event, ui ) {
                var num = periodInfo.length;

                var uwidth = parseInt(100/num);
                var pid = 0;
               
               
                // if(ui.value > (num) * uwidth) {ui.value = pid * uwidth;}
                //计算滑条移动产生的月份数
                $("#buy_num").val(ui.value)
                
                
                $(".re1_t2").html("&nbsp;月");
                $(".i-month").html(ui.value);
                 //计算费用
                 stairPrice();

            }
        });

        var slider_time_1 = $("#slider_time_1").slider({
            values:[],
            animate:true,
            min:0,
            max:12,
            step:1,
            range:'min',
            change: function( event, ui ) {
                var num = periodInfo.length;

                var uwidth = parseInt(100/num);
                var pid = 0;
               
               
                // if(ui.value > (num) * uwidth) {ui.value = pid * uwidth;}
                //计算滑条移动产生的月份数
                $("#buy_num_1").val(ui.value)
                
                
                $(".re1_t2").html("&nbsp;月");
                 //计算费用
                 stairPrice_1();

            }
        });
    
        var slider_time_2 = $("#slider_time_2").slider({
            values:[],
            animate:true,
            min:0,
            max:12,
            step:1,
            range:'min',
            change: function( event, ui ) {
                var num = periodInfo.length;

                var uwidth = parseInt(100/num);
                var pid = 0;
               
               
                // if(ui.value > (num) * uwidth) {ui.value = pid * uwidth;}
                //计算滑条移动产生的月份数
                $("#buy_num_2").val(ui.value)
                
                
                $(".re1_t2").html("&nbsp;月");
                 //计算费用
                 stairPrice_2();

            }
        });

    	function tot_volume(){
               //获取手动输入的容量值
              var sid;
              var tot_volume = parseInt($("#tot_volume").val());
              var max_volume = spaceInfo[spaceInfo.length-1];

              var min_volume = spaceInfo[0];
              
              var num = spaceInfo.length;

              if(tot_volume > max_volume){
                  alert("对不起，最大存储容量不能超过"+max_volume+"M");
                  $("#tot_volume").val(max_volume);
                  tot_volume = max_volume;
                  sid = spaceInfo.length-1;

              }else if(tot_volume < min_volume){
                  alert("对不起，最小存储容量不能小于"+min_volume+"M");
                  $("#tot_volume").val(min_volume);
                  tot_volume = min_volume;
                  sid = 0;
              }else{
                 for(var key in spaceInfo){
                    if((tot_volume >= spaceInfo[key]) && (tot_volume <= spaceInfo[key+1])){
                      sid = parseInt(key);
                  
                      break;
                    }
                 }
              }
              
             //尝试计算一个拖拽滑条的长度，这个滑条的长度只能即可能的精确。所以拖拽滑条的长度不能用来计算容量
             
            //根据手动输入容量的值计算费用。
            var buy_num = $("#buy_num").val();

            var tot_volume_2;

           if(tot_volume==50){
            tot_volume_2=tot_volume*4;
           }
           else if(tot_volume<100&&tot_volume>50)
              {
              tot_volume_2=tot_volume*4;
           }else if(tot_volume==100)
               {
               tot_volume_2=tot_volume*4;
            }else if(tot_volume<200 &&tot_volume>100)
               {
               tot_volume_2=tot_volume*4;
            }else if(tot_volume==200)
               {
              tot_volume_2=tot_volume*3;
            }
            else if(tot_volume<500 &&tot_volume>200)
               {
               tot_volume_2=tot_volume*2.5;
            }else if(tot_volume==500)
              {
              tot_volume_2=tot_volume*1.6;
            }else if(tot_volume<1000 &&tot_volume>500)
              {
              tot_volume_2=tot_volume*1.2;

            }else if(tot_volume==1000)
               {
               tot_volume_2=tot_volume*1.07;
          
            }//else if(tot_volume<=600 &&tot_volume>500)
           //    {
           //    tot_volume_2=tot_volume*1.07;
           // }else if(tot_volume<=700 &&tot_volume>600)
           //    {
           //    tot_volume_2=tot_volume*1.04;
            
           // }else if(tot_volume<=800 &&tot_volume>700)
           //    {
           //    tot_volume_2=tot_volume*1.02;
            
           // }else if(tot_volume<=900 &&tot_volume>800)
           //    {
           //    tot_volume_2=tot_volume*1;
            
           // }else if(tot_volume<=1000 &&tot_volume>900)
           //    {
           //    tot_volume_2=tot_volume*0.96;
           //  }

            slider.slider( "value", tot_volume_2);
           $("#spaceSectionNum").val(sid+1);//隐蔽域记下 当前位于哪个计费区间

            
           $("#tot_volume").val(tot_volume);
            stairPrice();
        }	
              
      function tot_volume_1(){
               //获取手动输入的容量值
              var sid_1;
              var tot_volume_1 = parseInt($("#tot_volume_1").val());
              var max_volume_1 = spaceInfo[spaceInfo.length-1];

              var min_volume_1 = spaceInfo[0];
              
              var num_1 = spaceInfo.length;

              if(tot_volume_1 > max_volume_1){
                  alert("对不起，最大存储容量不能超过"+max_volume_1+"M");
                  $("#tot_volume_1").val(max_volume_1);
                  tot_volume_1 = max_volume_1;
                  sid_1 = spaceInfo.length-1;

              }else if(tot_volume_1 < min_volume_1){
                  alert("对不起，最小存储容量不能小于"+min_volume_1+"M");
                  $("#tot_volume_1").val(min_volume_1);
                  tot_volume_1 = min_volume_1;
                  sid_1 = 0;
              }else{
                 for(var key in spaceInfo){
                    if((tot_volume_1 >= spaceInfo[key]) && (tot_volume_1 <= spaceInfo[key+1])){
                      sid_1 = parseInt(key);
                  
                      break;
                    }
                 }
              }
              
             //尝试计算一个拖拽滑条的长度，这个滑条的长度只能即可能的精确。所以拖拽滑条的长度不能用来计算容量
             
            //根据手动输入容量的值计算费用。
            var buy_num_1 = $("#buy_num_1").val();
            
           $("#spaceSectionNum_1").val(sid_1+1);//隐蔽域记下 当前位于哪个计费区间

           var tot_volume_2;

           if(tot_volume_1<=10){
            tot_volume_2=tot_volume_1*10;
           }else if(tot_volume_1<=50 &&tot_volume_1>10)
              {
              tot_volume_2=tot_volume_1*2.5;
           }else if(tot_volume_1<=100 &&tot_volume_1>50)
              {
              tot_volume_2=tot_volume_1*1.6;
           }else if(tot_volume_1<=150 &&tot_volume_1>100)
              {
              tot_volume_2=tot_volume_1*1.5;
           }else if(tot_volume_1<=200 &&tot_volume_1>150)
              {
              tot_volume_2=tot_volume_1*1.42;
           }else if(tot_volume_1<=250 &&tot_volume_1>200)
              {
              tot_volume_2=tot_volume_1*1.28;
           }else if(tot_volume_1<=300 &&tot_volume_1>250)
              {
              tot_volume_2=tot_volume_1*1.2;
           }else if(tot_volume_1<=400 &&tot_volume_1>300)
              {
              tot_volume_2=tot_volume_1*1.1;

           }else if(tot_volume_1<=500 &&tot_volume_1>400)
              {
              tot_volume_2=tot_volume_1*1.07;
          
           }else if(tot_volume_1<=600 &&tot_volume_1>500)
              {
              tot_volume_2=tot_volume_1*1.07;
           }else if(tot_volume_1<=700 &&tot_volume_1>600)
              {
              tot_volume_2=tot_volume_1*1.04;
            
           }else if(tot_volume_1<=800 &&tot_volume_1>700)
              {
              tot_volume_2=tot_volume_1*1.02;
            
           }else if(tot_volume_1<=900 &&tot_volume_1>800)
              {
              tot_volume_2=tot_volume_1*1;
            
           }else if(tot_volume_1<=1000 &&tot_volume_1>900)
              {
              tot_volume_2=tot_volume_1*0.96;
            }


            slider_1.slider( "value", tot_volume_2);
           $("#tot_volume_1").val(tot_volume_1);
            stairPrice_1();
        } 

      function tot_volume_2(){
               //获取手动输入的容量值
              var sid_2;
              var tot_volume_2 = parseInt($("#tot_volume_2").val());
              var max_volume_2 = spaceInfo[spaceInfo.length-1];

              var min_volume_2 = spaceInfo[0];
              
              var num_2 = spaceInfo.length;

              if(tot_volume_2 > max_volume_2){
                  alert("对不起，最大存储容量不能超过"+max_volume_2+"M");
                  $("#tot_volume_2").val(max_volume_2);
                  tot_volume_2 = max_volume_2;
                  sid_2 = spaceInfo.length-1;

              }else if(tot_volume_2 < min_volume_2){
                  alert("对不起，最小存储容量不能小于"+min_volume_2+"M");
                  $("#tot_volume_2").val(min_volume_2);
                  tot_volume_2 = min_volume_2;
                  sid_2 = 0;
              }else{
                 for(var key in spaceInfo){
                    if((tot_volume_2 >= spaceInfo[key]) && (tot_volume_2 <= spaceInfo[key+1])){
                      sid_2 = parseInt(key);
                  
                      break;
                    }
                 }
              }
              
             //尝试计算一个拖拽滑条的长度，这个滑条的长度只能即可能的精确。所以拖拽滑条的长度不能用来计算容量
             
            //根据手动输入容量的值计算费用。
            var buy_num_2 = $("#buy_num_2").val();
            
           $("#spaceSectionNum_2").val(sid_2+1);//隐蔽域记下 当前位于哪个计费区间

           var tot_volume_2_1;

           if(tot_volume_2<=10){
            tot_volume_2_1=tot_volume_2*10;
           }else if(tot_volume_2<=50 &&tot_volume_2>10)
              {
              tot_volume_2_1=tot_volume_2*2.5;
           }else if(tot_volume_2<=100 &&tot_volume_2>50)
              {
              tot_volume_2_1=tot_volume_2*1.6;
           }else if(tot_volume_2<=150 &&tot_volume_2>100)
              {
              tot_volume_2_1=tot_volume_2*1.5;
           }else if(tot_volume_2<=200 &&tot_volume_2>150)
              {
              tot_volume_2_1=tot_volume_2*1.42;
           }else if(tot_volume_2<=250 &&tot_volume_2>200)
              {
              tot_volume_2_1=tot_volume_2*1.28;
           }else if(tot_volume_2<=300 &&tot_volume_2>250)
              {
              tot_volume_2_1=tot_volume_2*1.2;
           }else if(tot_volume_2<=400 &&tot_volume_2>300)
              {
              tot_volume_2_1=tot_volume_2*1.1;

           }else if(tot_volume_2<=500 &&tot_volume_2>400)
              {
              tot_volume_2_1=tot_volume_2*1.07;
          
           }else if(tot_volume_2<=600 &&tot_volume_2>500)
              {
              tot_volume_2_1=tot_volume_2*1.07;
           }else if(tot_volume_2<=700 &&tot_volume_2>600)
              {
              tot_volume_2_1=tot_volume_2*1.04;
            
           }else if(tot_volume_2<=800 &&tot_volume_2>700)
              {
              tot_volume_2_1=tot_volume_2*1.02;
            
           }else if(tot_volume_2<=900 &&tot_volume_2>800)
              {
              tot_volume_2_1=tot_volume_2*1;
            
           }else if(tot_volume_2<=1000 &&tot_volume_2>900)
              {
              tot_volume_2_1=tot_volume_2*0.96;
            }


            slider_2.slider( "value", tot_volume_2_1);
           $("#tot_volume_2").val(tot_volume_2);
            stairPrice_2();
        } 



        function buy_num(){

            var periodInfo=[1,2,3,4,5,6,7,8,9,10,11,12];

             var sid =0;
             var buy_num = parseInt($("#buy_num").val());

             var max_month = periodInfo[periodInfo.length-1];
             
             var min_month = periodInfo[0];
            
             if(buy_num>max_month){
                 alert("使用时长最多为"+max_month+"个月");
                 $("#buy_num").val(max_month);
                 buy_num = max_month;
                 sid=periodInfo.length-1;

                 
             }else if(buy_num<min_month){
                 alert("对不起，使用时长不能小于"+min_month+"月");
                 $("#buy_num").val(min_month);
                 buy_num = min_month;
                 sid=0;
             }
             else{
                  for(var key in periodInfo){
                    if(buy_num == periodInfo[key]){
                       sid = parseInt(key);
                      break;

                    }
                }
             }

             // var uwidth=buy_num*12;
            

            //  //根据手动输入时长计算费用。
            var tot_volume = $("#tot_volume").val();
            $("#timeSectionNum").val(sid+1);//隐蔽域记下 当前位于哪个计费区间
             slider_time.slider( "value", buy_num);
            // $("#buy_num").val(buy_num);
            stairPrice();
	}
     function buy_num_1(){

            var periodInfo=[1,2,3,4,5,6,7,8,9,10,11,12];

             var sid=0;
             var buy_num = parseInt($("#buy_num_1").val());

             var max_month = periodInfo[periodInfo.length-1];
             
             var min_month = periodInfo[0];
            
             if(buy_num>max_month){
                 alert("使用时长最多为"+max_month+"个月");
                 $("#buy_num_1").val(max_month);
                 buy_num = max_month;
                 sid=periodInfo.length-1;

                 
             }else if(buy_num<min_month){
                 alert("对不起，使用时长不能小于"+min_month+"月");
                 $("#buy_num_1").val(min_month);
                 buy_num = min_month;
                 sid=0;
             }
             else{
                  for(var key in periodInfo){
                    if(buy_num == periodInfo[key]){
                       sid = parseInt(key);
                      break;

                    }
                }
             }

             // var uwidth=buy_num*12;
            

            //  //根据手动输入时长计算费用。
            var tot_volume = $("#tot_volume_1").val();
            $("#timeSectionNum_1").val(sid+1);//隐蔽域记下 当前位于哪个计费区间
             slider_time_1.slider( "value", buy_num);
            // $("#buy_num").val(buy_num);
            stairPrice_1();
  }

     function buy_num_2(){

            var periodInfo=[1,2,3,4,5,6,7,8,9,10,11,12];

             var sid=0;
             var buy_num = parseInt($("#buy_num_2").val());

             var max_month = periodInfo[periodInfo.length-1];
             
             var min_month = periodInfo[0];
            
             if(buy_num>max_month){
                 alert("使用时长最多为"+max_month+"个月");
                 $("#buy_num_2").val(max_month);
                 buy_num = max_month;
                 sid=periodInfo.length-1;

                 
             }else if(buy_num<min_month){
                 alert("对不起，使用时长不能小于"+min_month+"月");
                 $("#buy_num_2").val(min_month);
                 buy_num = min_month;
                 sid=0;
             }
             else{
                  for(var key in periodInfo){
                    if(buy_num == periodInfo[key]){
                       sid = parseInt(key);
                      break;

                    }
                }
             }

             // var uwidth=buy_num*12;
            

            //  //根据手动输入时长计算费用。
            var tot_volume = $("#tot_volume_2").val();
            $("#timeSectionNum_2").val(sid+1);//隐蔽域记下 当前位于哪个计费区间
             slider_time_2.slider( "value", buy_num);
            // $("#buy_num").val(buy_num);
            stairPrice_2();
  }


	     //监听buy_num输入回车事件
        $("#buy_num").keypress(function(e){
             switch(e.which)    
             {    
                case 13:  buy_num();
   

                
             }      
        })

       $("#buy_num_1").keypress(function(e){
             switch(e.which)    
             {    
                case 13:  buy_num_1();
   

                
             }      
        })

       $("#buy_num_2").keypress(function(e){
             switch(e.which)    
             {    
                case 13:  buy_num_2();
   

                
             }      
        })
        $("#tot_volume").keypress(function(e){
             switch(e.which)    
             {    
                case 13:tot_volume();  
                
             }    
        })
        $("#tot_volume_1").keypress(function(e){
             switch(e.which)    
             {    
                case 13:tot_volume_1();  
                
             }    
        })

          $("#tot_volume_2").keypress(function(e){
             switch(e.which)    
             {    
                case 13:tot_volume_2();  
                
             }    
        })      

        //手动输入数量触发的费用更改
        $("#buy_num").blur(function(){
           buy_num();  
        })        //手动输入数量触发的费用更改
        $("#buy_num_1").blur(function(){
           buy_num_1();  
        })
         $("#buy_num_2").blur(function(){
           buy_num_2();  
        })
       

        //手动输入容量触发的费用更改
        $("#tot_volume").blur(function(){
        if($.trim($("#tot_volume").val())=="")
          $("#tot_volume").val(1);
           tot_volume();
        })
        //手动输入容量触发的费用更改
        $("#tot_volume_1").blur(function(){
        if($.trim($("#tot_volume_1").val())=="")
          $("#tot_volume_1").val(1);
           tot_volume_1();
        })
        //手动输入容量触发的费用更改
        $("#tot_volume_2").blur(function(){
        if($.trim($("#tot_volume_2").val())=="")
          $("#tot_volume_2").val(1);
           tot_volume_2();
        })

        
        create_section();
        tot_volume();
        buy_num();   

       create_section_1();
        tot_volume_1();
        buy_num_1();   

        create_section_2();
        tot_volume_2();
        buy_num_2();  
    });

    //点击加速类型    
    $("#spaceUpType li").eq(0).click(function(){
    $(this).toggleClass("cur")
    if($("#spaceUpType .cur").size()<1)
    {alert("至少选择一项服务！");
    $("#spaceUpType li:first").addClass("cur");//至少选择一项
    }
    stairPrice();
    return false;
    })


    
 //   $.formValidator.initConfig({autotip:true,formid:"myform",onerror:function(msg){}});
